{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append('../')\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import steward as st\n",
    "import matplotlib.pyplot as plt\n",
    "import pickle\n",
    "import xgboost\n",
    "from sklearn.metrics import roc_auc_score\n",
    "%matplotlib inline\n",
    "from src import build\n",
    "from src import train, config\n",
    "from src.feature_cols import to_drop\n",
    "import h5py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "build.build_all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "f = h5py.File(config.pj_root + 'data/feature_train_all.hdf5', 'r')\n",
    "use_n = 7724875 #所有训练集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X = f['default'][0:use_n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y = 'basic_preprocess/y_train_all'\n",
    "y_df = st.get_instance(y).load()[0:use_n]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'n_estimators': 600, 'objective': 'rank:pairwise', 'gamma': 0.06, 'learning_rate': 0.3, 'max_depth': 5}\n",
      "start training...\n"
     ]
    }
   ],
   "source": [
    "n=800\n",
    "model_para = {\n",
    "    'objective': 'rank:pairwise',\n",
    "    'n_estimators': n,\n",
    "    'learning_rate': 0.3,\n",
    "    'max_depth': 4,\n",
    "}\n",
    "print(model_para)\n",
    "train.train_all(X, y_df, model_para=model_para, raw=True, tag='d4iter%d' % (n))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "n=600\n",
    "model_para = {\n",
    "    'objective': 'rank:pairwise',\n",
    "    'n_estimators': n,\n",
    "    'learning_rate': 0.3,\n",
    "    'max_depth': 5,\n",
    "    'subsample': 0.9, \n",
    "    'gamma': 0.06,\n",
    "    'reg_alpha': 1\n",
    "}\n",
    "print(model_para)\n",
    "train.train_all(X, y_df, model_para=model_para, raw=True, tag='d5iter%dsubsample0.9gamma0.06reg_alpha1' % (n))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
